﻿/**
 * Created by cyf on 15-12-1.
 * 好友树构建器
 */
(function() {
	qxchat.Tray = Tray;
	var EXTEND = null; //是否需要继承
	function Tray() {
		if (EXTEND) {
			EXTEND.apply(this, arguments);
		}
		this.isShowWindow = true;
		var gui = require('nw.gui');
		this.win = gui.Window.get();
		this.tray = new gui.Tray({
			title: 'QxChat',
			icon: 'qx.png'
		});

		this.tray.tooltip = 'QxChat';
		var self = this;
		//Menu
		var menu = new gui.Menu();
		menu.append(new gui.MenuItem({
			type: 'normal',
			label: '主界面',
			click: function() {
				if (self.isShowWindow) {
					self.win.hide();
					self.isShowWindow = false;
				} else {
					self.win.show();
					self.isShowWindow = true;
				}
			}
		}));
		menu.append(new gui.MenuItem({
			type: 'normal',
			label: '退出',
			click: function() {
				try {
					var gui = require('nw.gui');
					gui.App.closeAllWindows();
				} catch(e) {
					var gui = require('nw.gui');
					gui.App.quit();
				}
			}
		}))
		this.tray.menu = menu;

		//Click to show/hide;
		this.tray.on('click',
			function() {
				if (self.isShowWindow) {
					self.win.hide();
					self.isShowWindow = false;
				} else {
					self.win.show();
					self.isShowWindow = true;
				}
			});
	}
})();